﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace diploma
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bit1 = new Bitmap(panel1.Width, panel1.Height);
            panel1.DrawToBitmap(bit1, new Rectangle(0, 0, panel1.Width, panel1.Height));
            int border = (panel1.Width - panel1.ClientSize.Width) / 2;//边框宽度
            int caption = (panel1.Height - panel1.ClientSize.Height) - border;//标题栏高度
            //Bitmap bit2 = bit1.Clone(new Rectangle(border, caption, panel1.ClientSize.Width, panel1.ClientSize.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            bit1.Save("E:\\AAA.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);//包括标题栏和边框
            //bit2.Save("E:\\BBB.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);//不包括标题栏和边框
            bit1.Dispose();
            //bit2.Dispose();
        }
    }
}
